require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/react-native-permissions/scripts/setup'

platform :ios, '15.1'
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

# 配置 react-native-permissions 需要的权限
setup_permissions([
  'LocationWhenInUse',
  'Microphone',
  'SpeechRecognition',
])

target 'BellaTravel' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/..",
    :new_arch_enabled => false,
    # 启用 Hermes 引擎以提升性能
    :hermes_enabled => true
  )

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.1'
        
        
        # 修复架构配置冲突
        if target.name == 'BellaTravel'
          config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = '$(inherited)'
        end
      end
    end
  end
end
